package edu.whut.mall.${Module}.controller;

import edu.whut.mall.${Module}.domain.${ClassName}Params;
import edu.whut.mall.${Module}.service.I${ClassName}Service;
import edu.whut.mall.common.api.CommonPage;
import edu.whut.mall.common.api.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Slf4j
@RequiredArgsConstructor
@RequestMapping("/${className}")
@RestController
@Api(value="${myComment}管理器",tags = {"${myComment}管理器"})
public class Rest${ClassName}Controller {

    private final I${ClassName}Service ${className}Service;

    @ApiOperation("添加${myComment}")
    @PostMapping(value = "/addOne${ClassName}")
    public CommonResult addOne${ClassName}(@Valid @RequestBody ${ClassName}Params ${className}Params){
        int result = ${className}Service.insertOne${ClassName}(${className}Params);
        if (result <= 0) {
            return CommonResult.failed("添加${myComment}失败");
        }
        return CommonResult.success("添加${myComment}成功");
    }

    @ApiOperation("更新${myComment}")
    @PostMapping(value = "/updateOne${ClassName}")
    public CommonResult updateOne${ClassName}(@Valid @RequestBody ${ClassName}Params ${className}Params){
        int result = ${className}Service.updateOne${ClassName}(${className}Params);
        if (result <= 0) {
            return CommonResult.failed("更新${myComment}失败");
        }
        return CommonResult.success("更新${myComment}成功");
    }
}